#include <imx6q/mmpf0100.h>



int mmpf0100_init(struct mmpf0100 *obj)
{
	unsigned char val;

	val = mmpf0100_read(obj, 0x03);
	if (val != 0x10)
		return -1;
	return 0;
}

int mmpf0100_set_swmode(mmpf0100 *obj, unsigned char swx, unsigned char mode)
{
	if (swx == 0) {
		mmpf0100_write(obj, mode, 0x23);
	} else {
		mmpf0100_write(obj, mode, 0x31 + (swx-1)*7);
	}
	return 0;
}

//---------------------------------------------------------------------------------------------------------------------
//	Platform
//---------------------------------------------------------------------------------------------------------------------

/* Uboot */
#include <common.h>
#include <malloc.h>
#include <i2c.h>
/* Uboot */

mmpf0100* mmpf0100_alloc(mmpf0100_config *config)
{
	mmpf0100 *obj;

	obj = malloc(sizeof(mmpf0100));
	if (obj == NULL)
		return NULL;
	
	if (config == NULL) {
		obj->config.busnum = 1;
		obj->config.chip   = 0x08;
	} else {
		obj->config = *config;
	} 
	
	return obj;
}

void mmpf0100_write(mmpf0100 *obj, unsigned char val, unsigned char addr)
{
	i2c_set_bus_num(obj->config.busnum);
	i2c_write(obj->config.chip, addr, 1, &val ,1);
}

unsigned char mmpf0100_read(mmpf0100 *obj, unsigned char addr)
{
	unsigned char val;

	i2c_set_bus_num(obj->config.busnum);
	i2c_read(obj->config.chip, addr, 1, &val ,1);
	return val;
}
